/*
 *  Copyright 2007 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.model.core;

import com.blandware.atleap.common.Constants;

import java.util.List;
import java.util.ArrayList;

/**
 * <p>Represents a definition attribute that is list and marked as a container.
 * </p>
 * <p><a href="TileContainer.java.html"><i>View source</i></a></p>
 *
 * @author Roman Puchkovskiy <a href="mailto:roman.puchkovskiy@blandware.com">
 *         &lt;roman.puchkovskiy@blandware.com&gt;</a>
 * @version $Revision: 1.3 $ $Date: 2007/04/27 11:42:51 $
 * @see com.blandware.atleap.model.core.TileListComponent
 * @hibernate.class table="`al_core_tile_container`" lazy="false"
 * @hibernate.cache usage="read-write"
 */
public class TileContainer extends BaseObject {
    /**
     * ID
     */
    protected Long id;
    /**
     * Name of definition to which container belongs
     */
    protected String definitionName;
    /**
     * Name of attribute
     */
    protected String listName;
    /**
     * Layout to which container belongs
     */
    protected Layout layout;
    /**
     * List of components
     */
    protected List tileListComponents = new ArrayList();

    /**
     * Default constructor.
     */
    public TileContainer() {
    }

    /**
     * Constructor that sets definition name and list name.
     *
     * @param definitionName definition name to set
     * @param listName list name to set
     */
    public TileContainer(String definitionName, String listName) {
        this.definitionName = definitionName;
        this.listName = listName;
    }

    /**
     * Returns ID.
     *
     * @return ID
	 * @hibernate.id column="`id`"
	 * generator-class="increment" unsaved-value="null"
     */
    public Long getId() {
        return id;
    }

    /**
     * Sets ID.
     *
     * @param id ID to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * Returns name of definition to which container belongs.
     *
     * @return definition name
	 * @hibernate.property
	 * @hibernate.column name="`definition_name`" not-null="true" unique="false"
     * length="252"
     */
    public String getDefinitionName() {
        return definitionName;
    }

    /**
     * Sets name of definition to which container belongs.
     *
     * @param definitionName name to set
     */
    public void setDefinitionName(String definitionName) {
        this.definitionName = definitionName;
    }

    /**
     * Returns name of list which is container.
     *
     * @return list name
	 * @hibernate.property
	 * @hibernate.column name="`list_name`" not-null="false" unique="false"
     * length="252"
     */
    public String getListName() {
        return listName;
    }

    /**
     * Sets name of list which is container.
     *
     * @param listName name to set
     */
    public void setListName(String listName) {
        this.listName = listName;
    }

    /**
     * Returns layout to which container belongs.
     *
     * @return layout
     * @hibernate.many-to-one column="`layout_id`" not-null="true"
     * outer-join="false" lazy="false"
     */
    public Layout getLayout() {
        return layout;
    }

    /**
     * Sets layout to which container belongs.
     *
     * @param layout layout to set
     */
    public void setLayout(Layout layout) {
        this.layout = layout;
    }

	/**
	 * Returns list of components which belong to this container.
	 *
	 * @return list of components
	 * @hibernate.list table="`al_core_tile_list_component`" lazy="false"
     * cascade="all-delete-orphan" outer-join="false"
	 * @hibernate.collection-key column="`tile_container_id`"
	 * @hibernate.collection-index column="`pos`"
	 * @hibernate.collection-composite-element class="com.blandware.atleap.model.core.TileListComponent"
	 * @hibernate.cache usage="read-write"
	 */
	public List getTileListComponents() {
		return tileListComponents;
	}

    /**
     * Sets list of components which belong to this container.
     *
     * @param tileListComponents list of components
     */
	public void setTileListComponents(List tileListComponents) {
		this.tileListComponents = tileListComponents;
	}

    /**
     * Adds a component to the list of components which belong to this
     * container.
     *
     * @param listComponent the component to be added
     */
	public void addListComponent(TileListComponent listComponent) {
		listComponent.setTileContainer(this);
		tileListComponents.add(listComponent);
	}

    /**
     * Removes a component from the list of components which belong to this
     * container.
     *
     * @param listComponent the component to be removed
     */
	public void removeListComponent(TileListComponent listComponent) {
		tileListComponents.remove(listComponent);
	}

    /**
     * Returns a full identifier.
     *
     * @return full identifier
     */
    public String getFullIdentifier() {
        return definitionName + Constants.TILE_CONTAINER_IDENTIFIER_SEPARATOR
                + listName;
    }

    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        TileContainer container = (TileContainer) o;

        if (definitionName != null ? !definitionName
                .equals(container.definitionName)
                : container.definitionName != null) {
            return false;
        }
        if (layout != null ? !layout.equals(container.layout)
                : container.layout != null) {
            return false;
        }
        if (listName != null ? !listName.equals(container.listName)
                : container.listName != null) {
            return false;
        }

        return true;
    }

    public int hashCode() {
        int result;
        result = (definitionName != null ? definitionName.hashCode() : 0);
        result = 31 * result + (listName != null ? listName.hashCode() : 0);
        result = 31 * result + (layout != null ? layout.hashCode() : 0);
        return result;
    }
}
